<?php

/**
 * money actions.
 *
 * @package    s-test
 * @subpackage money
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class moneyActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->forward('default', 'module');
  }
    /*L'Argent*/
  public function executePrepareMoney(sfWebRequest $request){
      $this->form = new KTDGiveMoneyForm();
  }
  public function executeGiveMoney(sfWebRequest $request){
    $this->form = new KTDGiveMoneyForm();
    $this->processForm($request, $this->form);
    //Si on a bien tout !
    if($this->form->isValid()){
         $values = $this->form->getValues();
         $amount = $values["amount"];
         $to = Doctrine::getTable('sfGuardUser')->findOneByPseudo($values["to"]);
         $from = $this->getUser()->getGuardUser();
         if($from->giveMoneyTo($amount, $to)){
            $this->getUser("notice", "L'argent a bien été transféré !");
            $from->save(); $to->save();
            $this->redirect("@homepage");
         }
         else
             $this->error = "Vous n'avez pas assez d'argent !";
    }
    $this->setTemplate('prepareMoney');
  }
  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));

    if ($form->isValid())
    {
        //
    }
  }
}
